class Solution {
public:
    bool canSortArray(vector<int>& nums)
    {
        //8 15 4 2 30
        //相邻 二进制的1数目相同 才能
        int n = nums.size();
        vector<pair<int, int>> tmp(n);

        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            for (int j = 0; j < 32; j++)
                if (((nums[i] >> j) & 1) == 1) cnt++;
            tmp[i] = { nums[i], cnt };
        }
        sort(nums.begin(), nums.end());

        for (int i = 0; i < n; i++)//n次
        {
            for (int j = 0; j < n - 1; j++)
            {
                int k = j + 1;
                if ((tmp[j].second == tmp[k].second) && (tmp[j].first > tmp[k].first))
                    swap(tmp[j], tmp[k]);
            }
        }
        vector<int> tmp1;
        for (auto& a : tmp)
            tmp1.push_back(a.first);

        return nums == tmp1 ? true : false;
    }
};